package com.travel.admin.thread;
import com.travel.admin.enums.LogLevelEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @desc:  日志线程,单线程异步线程处理日志
 */
public class LogThread implements Runnable {

    private Logger logger = LoggerFactory.getLogger(LogThread.class);

    private Object[] message;
    private String key;
    private LogLevelEnum logLevel;

    public LogThread(LogLevelEnum logLevel, String key, Object... message){
        this.logLevel = logLevel;
        this.key = key;
        this.message = message;
    }

    @Override
    public void run() {

        try {
            switch (logLevel){
                case WARN:
                    logger.warn(key,message);
                    break;
                case INFO:
                    logger.info(key,message);
                    break;
                case ERROR:
                    logger.error(key,message);
                    break;
                case DEBUG:
                    logger.debug(key,message);
                    break;
            }
        } catch (Exception e) {
            logger.error("打印日志异常{}",e);
        }
    }

}
